﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Model
{
    public class DataAccess
    {        
        public DataAccess()
        {
        }

        public DataView StudentsDataView
        {
            get
            {
                return new DataView(StudentDataSet.Instance.Student);                
            }
            
        }

        public StudentDataSet.StudentRow CreateNewRow()
        {
            StudentDataSet.StudentDataTable students = StudentDataSet.Instance.Student;
            return students.NewStudentRow();
        }

        public void AddNewRow(StudentDataSet.StudentRow row)
        {
            if (row == null)
                throw new ArgumentNullException("row");

            StudentDataSet.StudentDataTable students = StudentDataSet.Instance.Student;
            
            students.AddStudentRow(row);            
            students.AcceptChanges();
        }

        public int getNextStudentId()
        {
            int maxID = -1;
            foreach (StudentDataSet.StudentRow row in StudentDataSet.Instance.Student.Rows)
            {
                if (maxID < row.Id)
                    maxID = row.Id;
            }
            return maxID+1;
        }
    }
}
